package com.gamepad;

import mobilefeel.sdk.MobileFeelActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class ModoActivity extends MobileFeelActivity {
	 
	static final String[] MODOS = new String[] {"Gamepad 2+2 Botones", "Gamepad 4+2 Botones A",
		"Gamepad 4+2 Botones B", "Gamepad 6+2 Botones A", "Gamepad 6+2 Botones B", "Gamepad 8+2 Botones A", 
		"Gamepad 8+2 Botones B", "Gamepad 8+2 Botones C", "Gamepad 10+2 Botones", "Wheel Pedales+2", 
		"Wheel Pedales/Marchas+2", "Wheel Pedales/Marchas/Botones+2",};
	static final int MODO_GAMEPAD_2BOTONES = 0;
	static final int MODO_GAMEPAD_4BOTONES_A = 1;
	static final int MODO_GAMEPAD_4BOTONES_B = 2;
	static final int MODO_GAMEPAD_6BOTONES_A = 3;
	static final int MODO_GAMEPAD_6BOTONES_B = 4;
	static final int MODO_GAMEPAD_8BOTONES_A = 5;
	static final int MODO_GAMEPAD_8BOTONES_B = 6;
	static final int MODO_GAMEPAD_8BOTONES_C = 7;
	static final int MODO_GAMEPAD_10BOTONES = 8;
	static final int MODO_WHEEL_2BOTONES = 9;
	static final int MODO_WHEEL_4BOTONES = 10;
	static final int MODO_WHEEL_6BOTONES = 11;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
        setContentView(R.layout.modo);

		ListView listView = (ListView)findViewById(R.id.lista);
        listView.setAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, MODOS));
        listView.setTextFilterEnabled(true);
        
        listView.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				Intent i = null;
				switch (position) {
					case MODO_GAMEPAD_2BOTONES:
						i = new Intent(ModoActivity.this, GamepadActivity.class);
						i.putExtra("LAYOUT", R.layout.gamepad2);
						break;
					case MODO_GAMEPAD_4BOTONES_A:
						i = new Intent(ModoActivity.this, GamepadActivity.class);
						i.putExtra("LAYOUT", R.layout.gamepad4a);
						break;
					case MODO_GAMEPAD_4BOTONES_B:
						i = new Intent(ModoActivity.this, GamepadActivity.class);
						i.putExtra("LAYOUT", R.layout.gamepad4b);
						break;
					case MODO_GAMEPAD_6BOTONES_A:
						i = new Intent(ModoActivity.this, GamepadActivity.class);
						i.putExtra("LAYOUT", R.layout.gamepad6a);
						break;
					case MODO_GAMEPAD_6BOTONES_B:
						i = new Intent(ModoActivity.this, GamepadActivity.class);
						i.putExtra("LAYOUT", R.layout.gamepad6b);
						break;
					case MODO_GAMEPAD_8BOTONES_A:
						i = new Intent(ModoActivity.this, GamepadActivity.class);
						i.putExtra("LAYOUT", R.layout.gamepad8a);
						break;
					case MODO_GAMEPAD_8BOTONES_B:
						i = new Intent(ModoActivity.this, GamepadActivity.class);
						i.putExtra("LAYOUT", R.layout.gamepad8b);
						break;
					case MODO_GAMEPAD_8BOTONES_C:
						i = new Intent(ModoActivity.this, GamepadActivity.class);
						i.putExtra("LAYOUT", R.layout.gamepad8c);
						break;
					case MODO_GAMEPAD_10BOTONES:
						i = new Intent(ModoActivity.this, GamepadActivity.class);
						i.putExtra("LAYOUT", R.layout.gamepad10);
						break;
					case MODO_WHEEL_2BOTONES:
						i = new Intent(ModoActivity.this, WheelActivity.class);
						i.putExtra("LAYOUT", R.layout.wheel2);
						break;
					case MODO_WHEEL_4BOTONES:
						i = new Intent(ModoActivity.this, WheelActivity.class);
						i.putExtra("LAYOUT", R.layout.wheel4);
						break;
					case MODO_WHEEL_6BOTONES:
						i = new Intent(ModoActivity.this, WheelActivity.class);
						i.putExtra("LAYOUT", R.layout.wheel6);
						break;
				}
				startActivity(i);
			}
		});
		
	}
	
	@Override
	protected void onDestroy() {
		super.onDestroy(false);
	}
	
	@Override
	public void onBackPressed() {
		disconnect();
		super.onBackPressed();
	}

	@Override
	protected void onDisconnection(boolean remote) {
		Toast.makeText(this, "Desconectado", Toast.LENGTH_SHORT).show();
		if (remote)
			super.onBackPressed();
	}

	
}
